package Thread;/*
 *
 *@author:    Xavier
 *@data:      2024 - 01 - 12
 *@time:      15:20
 *
 */

public class Demo10 {
    public static void main(String[] args) {
        Thread b = new Thread(()->{
            for (int i = 0; i < 5; i++) {
                System.out.println("hello b");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("b over!");
        });

        Thread a = new Thread(()->{
            for (int i = 0; i < 3; i++) {
                System.out.println("hello a");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            // 如果b此时还没有结束，b.join()就会产生阻塞的情况，知道b先执行完
            try {
                b.join();// 加了这样就是b先执行完，没加就是a先执行完
                // ()里面可以加入时间为限制，单位ms
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("a over!");
        });

        b.start();
        a.start();
    }
}
